
/**   
 * @Title: MenusDao.java 
 * @Package com.neusoft.neumooc.dao 
 * @Description: TODO 
 * @author acer   
 * @date 2016年10月28日 下午5:20:06 
*/
package com.neusoft.neumooc.dao;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.neusoft.core.common.BaseDAO;
import com.neusoft.core.common.exception.DAOException;
import com.neusoft.neumooc.VO.MenuVO;
/** 
 * @ClassName: MenusDao 
 * @Description: TODO 
 * @author fancy
 * @date 2016年10月28日
 */
@Repository
public class MenusDaoImpl extends BaseDAO implements MenusDao 
{ /** 
	 * @Fields QUERY_MENU : TODO 获得菜单列表
	 */ 
	private final static String QUERY_MENU = "select wemall_menu.name,wemall_menu.id,wemall_menu.pid from wemall_menu";//获取菜单全部信息(分页)
	/** 
	 * @Fields QUERY_MENU_COUNT : TODO 获取菜单数量
	 */ 
	private final static String QUERY_MENU_COUNT = "select count(1) from  wemall_menu";//获取菜单数量
	/** 
	 * @Fields QUERR_INSERTS_MENU : TODO 添加菜单
	 */ 
	private final static String QUERR_INSERTS_MENU = "insert into wemall_menu(id,name,pid)values(:id,:name,:pid)";//添加菜单
	/** 
	 * @Fields DELETE_MENU : TODO 删除菜单
	 */ 
	private final static String DELETE_MENU = "delete from wemall_menu where id=?";//删除菜单
	/** 
	 * @Fields REQUIRE_MENU : TODO 获取菜单
	 */ 
	private final static String REQUIRE_MENU = "select wemall_menu.name,wemall_menu.id,wemall_menu.pid from wemall_menu where id=?";//获取菜单信息
	/** 
	 * @Fields UPDATE_MENU : TODO 更新菜单
	 */ 
	private static final String UPDATE_MENU = "update wemall_menu set name=:name,pid=:pid where id=:id";//更新菜单信息
	/** 
	 * @Fields INSERT_REPEAT : TODO 判断是否重复
	 */ 
	private static final String INSERT_REPEAT = "select count(1) from wemall_menu where wemall_menu.name=?";//判断是否重复
	/**
	 * @Title: queryMenuDao
	 * @Description: TODO
	 * @return
	 * @throws DAOException
	 */
	@Override
	public int queryMenuCount() throws DAOException {

		return this.queryInteger(QUERY_MENU_COUNT);
	}
	/**
	 * @Title: getMenus
	 * @Description: TODO
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws DAOException
	 */
	@Override
	public List<MenuVO> getMenus(int pageNo, int pageSize) throws DAOException {
		return this.getPageData(QUERY_MENU, MenuVO.class, pageNo, pageSize);	
	}
	/**
	 * @Title: addMenu
	 * @Description: TODO
	 * @param MenuVO menuvo
	 * @throws DAOException
	 */
	@Override
	public void addMenu(MenuVO menuvo) throws DAOException 
	{   
		
		this.update(QUERR_INSERTS_MENU,menuvo);
		
	}
	/**
	 * @Title: deleteBook
	 * @Description: TODO
	 * @param id
	 * @throws DAOException
	 */
	@Override
	public int deleteMenu(String id) throws DAOException {
		return this.update(DELETE_MENU, new Object[] { id });
	}
	/** 
	 * @Title: EditMenu 
	 * @Description: TODO 
	 * @param id
	 * @throws DAOException
	 */
	@Override
	public MenuVO menuInfo(String id) throws DAOException 
	{
		return  this.queryForBean(REQUIRE_MENU, MenuVO.class,new Object[]{id});
	}
	/** 
	 * @Title: updateMenu
	 * @Description: TODO 
	 * @param menuvo
	 * @throws DAOException
	 */
	@Override
	public void updateMenu(MenuVO menuVO) throws DAOException 
	{
		this.update(UPDATE_MENU, menuVO);
	}
	/** 
	 * @Title: getMenuList 
	 * @Description: TODO 获得菜单列表
	 * @return
	 * @throws DAOException
	 */
	@Override
	public List<MenuVO> getMenuList() throws DAOException 
	{
		return this.queryForBeanList(QUERY_MENU,MenuVO.class);
	}
	/** 
	 * @Title: checkRepeat 
	 * @Description: TODO 
	 * @param name
	 * @return
	 * @throws DAOException
	 */
	@Override
	public boolean checkRepeat(String name) throws DAOException 
	{   
		int t= this.queryInteger(INSERT_REPEAT, new Object[]{name});	
		if(t!=1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
